<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui" xmlns:app="http://org.wsiz.vro/app"
	xmlns:appcc="http://java.sun.com/jsf/composite/components">

	<f:validateBean disabled="true">
		<p:fieldset legend="${msg.account}">
			<h:panelGrid columns="2" styleClass="aria-role-presentation">
				<appcc:outputLabel for="login" value="${msg.account_login}"
					required="true" />
				<p:inputText id="login" label="${msg.account_login}"
					value="#{account.login}" maxlength="80" rendered="#{not readonly}">
					<f:validateBean binding="#{lenientBeanValidator}" />
				</p:inputText>
				<h:outputText value="#{account.login}" rendered="#{readonly}" />

				<appcc:outputLabel for="password" value="${msg.account_password}"
					required="true" />
				<p:inputText id="password" label="${msg.account_password}"
					value="#{account.password}" type="password"
					rendered="#{not readonly}">
					<f:validateBean binding="#{lenientBeanValidator}" />
				</p:inputText>
				<h:outputText value="********" rendered="#{readonly}" />

				<appcc:outputLabel for="email" value="${msg.account_email}"
					required="true" />
				<p:inputText id="email" label="${msg.account_email}"
					value="#{account.email}" maxlength="80" rendered="#{not readonly}">
					<f:validateBean binding="#{lenientBeanValidator}" />
				</p:inputText>
				<h:outputText value="#{account.email}" rendered="#{readonly}" />

				<appcc:outputLabel for="isEnabled" value="${msg.account_isEnabled}" />
				<h:selectBooleanCheckbox id="isEnabled"
					label="${msg.account_isEnabled}" value="#{account.isEnabled}"
					disabled="#{readonly}">
					<f:validateBean binding="#{lenientBeanValidator}" />
				</h:selectBooleanCheckbox>

				<appcc:outputLabel for="civility" value="${msg.account_civility}" />
				<p:inputText id="civility" label="${msg.account_civility}"
					value="#{account.civility}" maxlength="80"
					rendered="#{not readonly}">
					<f:validateBean binding="#{lenientBeanValidator}" />
				</p:inputText>
				<h:outputText value="#{account.civility}" rendered="#{readonly}" />

				<appcc:outputLabel for="firstName" value="${msg.account_firstName}" />
				<p:inputText id="firstName" label="${msg.account_firstName}"
					value="#{account.firstName}" maxlength="80"
					rendered="#{not readonly}">
					<f:validateBean binding="#{lenientBeanValidator}" />
				</p:inputText>
				<h:outputText value="#{account.firstName}" rendered="#{readonly}" />

				<appcc:outputLabel for="lastName" value="${msg.account_lastName}" />
				<p:inputText id="lastName" label="${msg.account_lastName}"
					value="#{account.lastName}" maxlength="80"
					rendered="#{not readonly}">
					<f:validateBean binding="#{lenientBeanValidator}" />
				</p:inputText>
				<h:outputText value="#{account.lastName}" rendered="#{readonly}" />

				<appcc:outputLabel for="birthDate" value="${msg.account_birthDate}" />
				<appcc:datePicker id="birthDate" label="${msg.account_birthDate}"
					value="#{account.birthDate}" rendered="#{not readonly}"
					timeRendered="true">
					<f:convertDateTime pattern="yyyy-MM-dd HH:mm" />
					<f:validateBean binding="#{lenientBeanValidator}" />
				</appcc:datePicker>
				<h:outputText value="#{account.birthDate}" rendered="#{readonly}">
					<f:convertDateTime pattern="yyyy-MM-dd HH:mm" />
				</h:outputText>



				<!-- note: bug prevent us from using appcc:outputLabel -->
				<label for="form:address_input">${msg.account_address}</label>
				<h:panelGrid columns="2" styleClass="aria-role-presentation">
					<p:autoComplete id="address" value="#{account.address}"
						label="${msg.account_address}"
						completeMethod="#{addressRepository.find}" var="item"
						itemValue="#{item}" itemLabel="#{addressConverter.print(item)}"
						converter="#{addressConverter}" rendered="#{not readonly}"
						size="50">
						<f:validateBean binding="#{lenientBeanValidator}" />
						<p:ajax event="itemSelect"
							listener="#{messageUtil.info('status_selected_ok',msg.account_address)}"
							update="messages" />
					</p:autoComplete>
					<h:outputText value="#{addressConverter.print(account.address)}"
						rendered="#{readonly}" />

					<h:panelGroup>
						<app:iconSearch action="selectAddress"
							title="${msg.account_address}" rendered="#{!readonly}" />
						<app:iconEdit action="editAddress" title="${msg.account_address}"
							rendered="#{!readonly and not empty account.address}" />
						<app:iconView action="viewAddress" title="${msg.account_address}"
							rendered="#{not empty account.address}" />
					</h:panelGroup>
				</h:panelGrid>


			</h:panelGrid>
			<app:saveButton title="${msg.account}" />
		</p:fieldset>
	</f:validateBean>
	<p:tabView id="tabs" activeIndex="#{tabBean.activeIndex}">
		<p:ajax event="tabChange" />


		<p:tab id="roles" title="${msg.account_roles}">
			<!-- Many To Many: roles -->
			<p:dataTable id="rolesList" var="item" value="#{roles}" width="100%"
				height="150px" paginator="true" paginatorAlwaysVisible="false"
				rows="10" currentPageReportTemplate="{currentPage} / {totalPage}"
				paginatorTemplate="{PreviousPageLink} {CurrentPageReport} {NextPageLink}"
				paginatorPosition="bottom">
				<f:facet name="header">
					<h:outputText value="roles list (many-to-many relation)" />
				</f:facet>

				<p:column id="role_roleName" headerText="${msg.role_roleName}"
					width="90%">
					<h:outputText value="#{item.roleName}" />
				</p:column>
				<p:column id="actions" width="9%">
					<f:facet name="header">
						<app:iconSearch action="searchRole" title="role"
							rendered="#{!readonly}" />
						<app:iconAdd action="addRole" title="role" disabled="#{readonly}" />
					</f:facet>
					<app:iconView action="viewRole"
						title="${roleConverter.print(item)}" />
					<app:iconDelete action="removeRole"
						update=":form:tabs :form:messages" disabled="#{readonly}"
						title="${roleConverter.print(item)}" />
				</p:column>
			</p:dataTable>
		</p:tab>
	</p:tabView>
</ui:composition>
